﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Popup;
using DevExpress.Utils.Win;
using DevExpress.XtraGrid.Editors;
using DevExpress.XtraLayout;
using DevExpress.XtraGrid.Demos.util;
using mendian;
using Luna小店.DTO;
using Luna小店.UC.面料库存.入库.service;
using Luna小店.UC.面料库存.库存记录.service;

namespace Luna小店.UC.面料库存
{
    public partial class Frm面料采购 : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        private List<DTO采购分录> DTO采购分录s = new List<DTO采购分录>();
        public Frm面料采购()
        {
            InitializeComponent();
        }

        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Frm面料选择 frm = new Frm面料选择();
            frm.ShowDialog();
            if (null == frm.DTO采购分录)
            {
                return;
            }
            this.DTO采购分录s.Add(frm.DTO采购分录);
            this.gridControl采购分录.DataSource = this.DTO采购分录s;
            this.gridView采购分录.RefreshData();
            try {
                this.textEdit总金额.Text = Convert.ToString(
                              Convert.ToDouble(this.textEdit总金额.Text) + (frm.DTO采购分录.quantity * frm.DTO采购分录.purchasePrice)
              );
            }
            catch { }
            
        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            PurchaseOrderDTO PurchaseOrderDTO = new PurchaseOrderDTO(
                this.dateTimePicker1.Value,
                Convert.ToDouble(this.textEdit总金额.Text),
                Convert.ToDouble(this.textEdit在途金额.Text),
                this.DTO采购分录s
                );
            //webservice传值
            入库Service.post其他入库(PurchaseOrderDTO);
            MessageBox.Show("采购入库成功");
        }

        private void textEdit在途金额_Validating(object sender, CancelEventArgs e)
        {
            if (!FunctionHelper.IsFloat(this.textEdit在途金额.Text))
            {
                MessageBox.Show("在途金额应为正数！");
                return;
            }
        }

        private void barButtonItem新增_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            new Frm新增面料期初().ShowDialog();
        }
    }
    
}